#include "stdafx.hpp"
#include "ColligereDatabaseInterfaceBase.hpp"

///////////////////////////////////////
// DatabaseProperties
///////////////////////////////////////

col::DatabaseProperties::DatabaseProperties ( DatabaseInterfaceBase &rInterface ) 
: mrInterface ( rInterface )
{
	mInFile = ( wxFileName ( wxFileExists ( rInterface.GetHandler()->GetInputFile() ) ?
		rInterface.GetHandler()->GetInputFile() : rInterface.GetHandler()->GetBufferFile() ) );
}

const wxString col::DatabaseProperties::GetFullPath() const 
{ 
	return mInFile.GetFullPath(); 
}

const wxString col::DatabaseProperties::GetHumanReadableFileSize() const 
{ 
	return mInFile.GetHumanReadableSize(); 
}

const wxString col::DatabaseProperties::GetCreationTime() const 
{ 
	wxDateTime cre;
	mInFile.GetTimes ( 0, 0, &cre );
	return cre.Format();
}

const wxString col::DatabaseProperties::GetModificationTime() const 
{
	wxDateTime mod;
	mInFile.GetTimes ( 0, &mod, 0 );
	return mod.Format();
}

const col::DatabaseProperties::ItemCountMap col::DatabaseProperties::GetItemCounts()
{
	DatabaseTableDeque tables = DatabaseTableListHandler::Get().GetTableList 
		( mrInterface.GetHandler()->GetTypeId() );

	wxASSERT ( tables.size() > 0 );

	ItemCountMap ret;

	foreach ( const DatabaseTable &t, tables )
	{
		ret[t.GetItemName()] = mrInterface.GetHandler()->GetRowCount(t);
	}
	return ret;
}

///////////////////////////////////////
// DatabaseInterfaceBase
///////////////////////////////////////

col::DatabaseInterfaceBase *col::DatabaseInterfaceBase::mpsActiveInterface = 0;